Skip to content

Fix service_create status/connection string bug when waiting#53

Merged
nathanjcochran merged 2 commits intomainfrom
nathan/password-wait-bug
Oct 10, 2025
Merged

Fix service_create status/connection string bug when waiting#53
nathanjcochran merged 2 commits intomainfrom
nathan/password-wait-bug

Conversation

@nathanjcochran
Copy link
Member

@nathanjcochran nathanjcochran commented Oct 10, 2025

Fixes a small bug I didn't notice when I first implemented #50.

Specifically, when the service_create MCP tool is called with with_password: true and wait: true, the password and connection string weren't being returned in the output, because after we finished polling to check if the service is ready, we replaced the entire service struct (which we had already modified with the connection string/password).

This fixes it by making the MCP version of waitForServiceReady just return the latest service status, rather than the entire service. This makes it work more like the command version of waitForServiceReady (we should really consolidate them, but I didn't want to deal with the logging/output differences right now - can tackle it if/when we overhaul logging in general).

Also fixed a very small bug in the command version of waitForServiceReady. See comment below.

@nathanjcochran nathanjcochran self-assigned this Oct 10, 2025

// waitForServiceReady polls the service status until it's ready or timeout occurs
func waitForServiceReady(client *api.ClientWithResponses, projectID, serviceID string, waitTimeout time.Duration, output io.Writer) (*api.DeployStatus, error) {
func waitForServiceReady(client *api.ClientWithResponses, projectID, serviceID string, waitTimeout time.Duration, initialStatus *api.DeployStatus, output io.Writer) (*api.DeployStatus, error) {
Copy link
Member Author

@nathanjcochran nathanjcochran Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a small bug I noticed when in the command version of waitForServiceReady, where the lastStatus returned from the command would be nil if it timed out before the first poll. Unlikely in practice, but technically possible if the --wait-timeout is less than 10 seconds (our polling interval).

The fix is just to pass in the service's initial status (from the create/fork request), and set the initial value of lastStatus to that.

Comment on lines -561 to +563
output.Service, err = s.waitForServiceReady(apiClient, cfg.ProjectID, serviceID, timeout, serviceStatus)
if err != nil {
if status, err := s.waitForServiceReady(apiClient, cfg.ProjectID, serviceID, timeout, service.Status); err != nil {
output.Message = fmt.Sprintf("Error: %s", err.Error())
} else {
output.Service.Status = util.DerefStr(status)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of the fix. Rather than overwriting output.Service with the latest polling result, we just overwrite output.Service.Status now (ensuring we don't overwrite the connection string/password set above).

@nathanjcochran nathanjcochran merged commit 7d68e3b into main Oct 10, 2025
2 checks passed
@nathanjcochran nathanjcochran deleted the nathan/password-wait-bug branch October 10, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants